package br.usp.pcs.lti.planning;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Utils {

    /**
     * Serializa um objeto.
     * 
     * @param object
     * @param fileName
     * @throws IOException
     */
    public static void serializeObject(Object object, String fileName) throws IOException {
        FileOutputStream fos = new FileOutputStream(fileName);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(object);
        oos.close();
    }

    /**
     * Desserializa um objeto.
     * 
     * @param fileName
     * @return objeto desserializado.
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public static Object deserializeObject(String fileName) throws IOException, ClassNotFoundException {
        FileInputStream fis = new FileInputStream(fileName);
        ObjectInputStream ois = new ObjectInputStream(fis);
        Object object = ois.readObject();
        ois.close();
        return object;
    }

}
